// 实现完全二叉树

package main

import (
	"fmt"
)

// 二叉树
type TreeNode struct {
	data  int
	left  *TreeNode
	right *TreeNode
}

// 先序遍历
func (treeNode *TreeNode) PreOrder() {
	if treeNode == nil {
		return
	}

	fmt.Print(treeNode.data, " ")
	treeNode.left.PreOrder()
	treeNode.right.PreOrder()
}

// 中序遍历
func (treeNode *TreeNode) MidOrder() {
	if treeNode == nil {
		return
	}

	treeNode.left.MidOrder()
	fmt.Print(treeNode.data, " ")
	treeNode.right.MidOrder()
}

// 后序遍历
func (treeNode *TreeNode) PostOrder() {
	if treeNode == nil {
		return
	}

	treeNode.left.PostOrder()
	treeNode.right.PostOrder()
	fmt.Print(treeNode.data, " ")
}

func main() {
	t := &TreeNode{data: 1}
	t.left = &TreeNode{data: 2}
	t.right = &TreeNode{data: 3}
	t.left.left = &TreeNode{data: 4}
	t.left.right = &TreeNode{data: 5}
	t.right.left = &TreeNode{data: 6}

	fmt.Print("先序遍历：")
	t.PreOrder()
	fmt.Print("\n中序遍历：")
	t.MidOrder()
	fmt.Print("\n后序遍历：")
	t.PostOrder()
	fmt.Println()

}
